﻿@using X.PagedList;
@using X.PagedList.Mvc.Core
@using OpenMms.Domain.Models
@model IPagedList<UserUpgrade>
@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/User/Views/_UserLayout.cshtml";
}
<!-- APP MAIN ==========-->
<main id="app-main" class="app-main">
    <div class="wrap">
        <section class="app-content">
            <div class="widget">
                <header class="widget-header title2">
                    <h4 class="widget-title">会员升级</h4>
                </header><!-- .widget-header -->
                <hr class="widget-separator">

                <div class="widget-body">
                    <form id="form1" class="form-horizontal">
                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">选择级别</label>
                            <div class="col-sm-5">
                                @*<select id="select2-demo-1" class="form-control" data-plugin="select2">
                                        <option value="option1">一级会员</option>
                                    </select>*@
                                @Html.DropDownList("database-dropdownlist", ViewBag.database as IEnumerable<SelectListItem>, new { @class = "form-control", @name = "AfterLevel", @id = "AfterLevel" })
                            </div><!-- END column -->
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">升级所需金额</label>
                            <div class="col-sm-5">
                                <input class="form-control" value="0" name="Amount" id="Amount" readonly="readonly" placeholder="">
                            </div>
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <label for="#" class="col-sm-2 control-label">二级密码</label>
                            <div class="col-sm-5">
                                <input class="form-control" type="password" name="SecondPassword" placeholder="" required>
                            </div>
                        </div><!-- .form-group -->

                        <div class="form-group">
                            <div class="col-sm-8 text-center">
                                @Html.AntiForgeryToken()
                                <button type="submit" class="btn btn-info">提交申请</button>
                            </div>
                        </div>
                    </form>
                </div><!-- .widget-body -->
            </div><!-- .widget -->
            <div class="widget">
                <header class="widget-header title2">
                    <h4 class="widget-title">会员升级记录</h4>
                </header><!-- .widget-header -->
                <hr class="widget-separator">

                <div class="widget-body mt15">
                    <div class="table-responsive">
                        <div class="text-center p-t-sm p-b-sm">
                            <nav class="page-redcolor">
                                <div id="showPage">
                                    @await Html.PartialAsync("List", Model)
                                </div>
                            </nav>

                        </div>

                    </div><!-- .widget-body -->
                </div>
            </div>
        </section><!-- #dash-content -->

    </div><!-- .wrap -->
    <!-- APP FOOTER -->
    <div class="wrap p-t-0">
        <footer class="app-footer">
            <div class="clearfix">
                <div class="copyright text-center w100">@OpenMms.Common.Url.NameConfig.companyName &copy;</div>
            </div>
        </footer>
    </div>
    <!-- /#app-footer -->
</main>
<script src="~/DirectSellJs/jquery.unobtrusive-ajax.min.js"></script>
<script>
    $('#form1').on('submit', function () {
        layer.confirm('确定要提交升级申请吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            formPost();
        }, function () {
            layer.close();
        });
        event.preventDefault() //阻止form表单默认提交
    })
    function formPost() {
        //加载层
        var index = layer.load(1, {
            shade: [0.1, '#fff']
        });
        $.ajax({
            type: "post",
            url: "/User/UserUpgrade/Upgrade",
            data: $('#form1').serialize(),
        }).success(function (message) {
            if (message.code != 200) {
                layer.msg(message.message, { icon: 2 });
            }
            else {
                layer.msg('升级申请提交成功,请等待管理员审核', {
                    time: 0 //不自动关闭
                    , btn: ['确定', '返回首页']
                    , btn1: function (index) {
                        location.reload();
                    }, btn2: function (index) {
                        location.href = "/User/Home/Index";
                    }
                });
            }
        }).fail(function (err) {
            layer.msg('系统错误,请稍后重试!', { icon: 2 });
        })
        layer.close(index)//关闭加载层
    }
    //计算差额
    $('#AfterLevel').on('change', function () {
        //加载层
        var index = layer.load(1, {
            shade: [0.1, '#fff']
        });
        var AfterLevel = $('#AfterLevel').val();
        if (AfterLevel != 0) {
            $.post("/User/UserUpgrade/Difference", { "AfterLevel": AfterLevel, }, function (data) {
                $("#Amount").val(data);
            });
        }
        else {
            $("#Amount").val(0);
        }
        layer.close(index)//关闭加载层
    });

</script>
